package com.car.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.car.entity.Carrentalorderform;
import com.car.entity.Cartypetable;
import com.car.entity.Servicings;
import com.car.page.Page;
import com.car.service.CardetailstableService;
import com.car.service.CarrentalorderformService;
import com.car.service.CartypetableService;
import com.car.service.ServicingServices;

@Controller
public class OrderController {
	@Autowired
	CarrentalorderformService corderService;
	
	@Autowired
	CartypetableService cartypetableService;
	
	@Autowired
	ServicingServices servicingService;
	
	@Autowired
	CardetailstableService cardetailstableService;
	
	@RequestMapping("/Carrentalorderform")
	public String carrentalorderform(Model model,String pageNo,String types){
	/*	List<Carrentalorderform>orderlist= corderService.selectAlls();
		model.addAttribute("orderlist",orderlist);*/
		if(types==null){
			types="1";
		}
		if(types.equals("1")){
			Page<Carrentalorderform>oderlist= corderService.selectOderPageList(pageNo==null?1:Integer.parseInt(pageNo), 10);
			model.addAttribute("orderlist",oderlist);
			model.addAttribute("types",types);
			return "Carrentalorderform";
		}else{
			Page<Carrentalorderform>oderlist= corderService.shenfengPageLsit(pageNo==null?1:Integer.parseInt(pageNo), 10);
			model.addAttribute("orderlist",oderlist);
			model.addAttribute("types",types);
			return "Carrentalorderform";
		}
		
	}
	@RequestMapping("/selectorderId")
	@ResponseBody
	public Object selectorderId(String orderId,String orderstate){
		if(orderstate.equals("0")){
			Carrentalorderform carrental = corderService.selectOderId(orderId);
			return carrental;
		}else{
			Carrentalorderform carrental = corderService.shunfengSelectOrderId(orderId);
			return carrental;
		}
	
		
	}
	@RequestMapping("/updateOrderState")
	@ResponseBody
	public Object updateOrderState(String orderId,String limitThe){
		int x = corderService.updateOrderState(orderId,limitThe);
		return x;
	}
	@RequestMapping("/selectTheRent")
	@ResponseBody
	public Object selectTheRent(int carId){
		Cartypetable car =  cartypetableService.selectTheRent(carId);
		return car;
	}
	@RequestMapping("/weixiu")
	@ResponseBody
	public Object servicingInsert(Servicings servicing){
		int xx = cardetailstableService.updateWeixiuCarId(servicing.getCarId());
		if(xx>0){
			int x = servicingService.servicingInsert(servicing);
			return x;
		}
		
		return 0;
	}
	@RequestMapping("/chaxun")
	@ResponseBody
	public Object chaxun(Model model ,String id,String types){
		if(types=="0"){
			types="1";
		}
		if(types.equals("1")){
			Carrentalorderform cc = corderService.selectOrderIdcha(id);
			
			return cc;
		}else{
			Carrentalorderform cc = corderService.shunfengOrderIdcha(id);
		
			return cc;
		}
		
	}
}
